package com.lixl.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * ThreadPoolExecutor是JDK中线程池的基础，ExcutorService/Executors的使用都依赖它 <a
 * href="http://blog.csdn.net/yuenkin/article/details/51040001"
 * >ThreadPoolExecutor源码解析</a>
 * <hr>
 * <a href="http://825635381.iteye.com/blog/2184680">与jdk1.6中实现有所不同</a>
 * 
 * @author Administrator
 *
 */
public class ThreadPoolExecutorDemo {

	public static void main(String[] args) {
		int corePoolSize = 10;	//核心线程数
		int maximumPoolSize = 30;//最大线程数
		long keepAliveTime = 30;
		TimeUnit unit = TimeUnit.MINUTES;//线程保持时间
		BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(10);//线程队列
		ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize,
				maximumPoolSize, keepAliveTime, unit, workQueue);

		for (int i = 0; i < 100; i++) {
			executor.execute(new Runnable() {
				@Override
				public void run() {
					System.out.println(Thread.currentThread().getName()
							+ " do something");
				}
			});
		}
		executor.shutdown();
	}

}
